import { Alova } from '@/utils/http/alova';

// 定义设备接口
export interface Device {
  id: number;
  name: string;
  status: string;
  rtsp_url: string;
  preview_image: string;
}

// 定义设备组接口
export interface DeviceGroup {
  id: string;
  name: string;
  children?: DeviceGroup[];
}

export interface AddDeviceForm {
  name: string;
  status: string; // 假设这是一个枚举类型，例如 'online' | 'offline' | 'maintenance'
  rtsp_url: string;
  group_id: string;
  preview_image: string;
}

export interface CaptureForm {
  device_id: number;
  rtsp_url: string;
}

export interface FormInst {
  group_id: string;
  name: string;
  gps: {
    latitude: number;
    longitude: number;
  }
  previewFiles: File;
  streamUrl: string;
}


// 获取设备列表
export function FetchDeviceList() {
  return  Alova.Get<Device[]>('/device/list');

}

// 获取分组列表
export async function FetchGroupList() {
  return Alova.Get<DeviceGroup[]>('/device-group/list');
}

// RTSP转HLS
export function RtspConvertHls(params) {
 return Alova.Get<String>('/video/convert',{
   params,
 });
}

export function RtspCapture(captureForm: CaptureForm) {
  return Alova.Post<String>('/video/capture',captureForm);
}

// 添加设备
export function AddDevice(addForm: AddDeviceForm) {
  return Alova.Post<Device>('/device/create', addForm);
}

//获取设备信息
export function GetDevice(deviceId: number) {
  return Alova.Get<Device>('/device/get/'+deviceId);
}

//删除设备
export function DeleteDevice(deviceId) {
  return Alova.Delete('/device/delete/'+deviceId);
}
